<?php
/**
 * ExtActiveRecord is the customized base CActiveRecord class.
 * It works with tale prefix
 * you can setup table prefix in config/main.php
 * 'params' => array(
 *	'tablePrefix' => 'app_'
 * ),
 */

class ExtActiveRecord extends CActiveRecord
{
    // Cache for table prefix so we don't have excessive overhead constantly retrieving it
    protected $tbl_prefix = null;
 
    /**
     * Force the child classes to use our table name prefixer
     */
    final public function tableName()
    {
        // If we haven't retrieved the table prefix yet
        if ($this->tbl_prefix === null)
        {
            // Fetch prefix
            $this->tbl_prefix = Yii::app()->params['tablePrefix'];
        }
 
        // Prepend prefix, call our new method
        return ($this->tbl_prefix . $this->_tableName());
    }
 
    /**
     * Function for child classes to implement to return the table name associated with it
     */
    protected function _tableName()
    {
        // Call the original method for our table name stuff
        return parent::tableName();
    }

}